#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2020/9/3 15:10
# @Author : 吴敬超
# explain:

import numpy as np
import netCDF4 as nc
import datetime
import csv
import math
# file_path = 'D:\NetCDFfile\ECMWF_mrt_20190101_v1.0_con.nc'
# file_path = 'D:/NetCDFfile/SALT_B.E.13.B1850C5.ne120_t12.sehires38.003.sunway_02.pop.h.0021-01.nc'

file_path = 'D:/NetCDFfile/3monsalt/SALT_B.E.13.B1850C5.ne120_t12.sehires38.003.sunway_02.pop.h.0021-01.nc'

file_obj = nc.Dataset(file_path)
# file_obj


odict_keys = file_obj.variables.keys()
print odict_keys
print len(odict_keys)
print odict_keys[0]

salt = file_obj.variables['SALT'][:]
lon = file_obj.variables['lon'][:]
lat = file_obj.variables['lat'][:]
z_t = file_obj.variables['z_t'][:]

time = file_obj.variables['time']
#
# for j in range(len(lon)):
#     print j
#
# for i in range(len(time)):
#     print i
#
# print time[:50]
#
# times = nc.num2date(time[:], 'days since 0000-01-01 00:00:00')
#
# print times[0].strftime("%Y-%m-%d %H:%M:%S")

print "**************"

salt_arr = salt[:]
print salt_arr.shape

print z_t[10]
print lat[10]
print lon[10]
print salt[0][0][1700][3500]
print "*******for*******"

# math.isnan(salt[0][0][0][0])
if str(salt[0][0][1700][3500])=='--':
    print 'xxxxxxxx'


if str(salt[0][0][0][0])=='--':
    print 'oooooooooooooooooooo'



#
# for ztnum in range(len(z_t)):
#     for latnum in range(len(lat)):
#         for lonnum in range(len(lon)):
#             print "*******in for*******"
#
#             print z_t[ztnum]
#             print lat[latnum]
#             print lon[lonnum]
#
#             print salt[0][ztnum][latnum][lonnum]




# missing_value = 9.96921E33

#
# print lat[len(lat)-1]
# print lon[len(lon)-1]
#
# print mrt[len(times)-1][len(lat)-1][len(lon)-1]

# print times[:12]

#
#
# for timets in range(len(times)):
#     for lata in range(len(lat)):
#         for lono in range(len(lon)):
#
#             print "time num is" + str(timets)
#             print "time :" + times[timets].strftime("%Y-%m-%d %H:%M:%S")
#
#
#             print "lat num is" + str(lata)
#             print "lat :" + str(lat[lata])
#
#             print "lon num is" + str(lono)
#             print "lon :" + str(lon[lono])

# print "mrt :" + mrt[timets][lata][lono]

#
# with open('D:/nccsv/mrt.csv', mode='wb') as ice_file:
#
#
#     ice_writer = csv.writer(ice_file,dialect='excel')
#     ice_writer.writerow(['time', 'lat', 'lon', 'mrt'])
#
#
#     for timets in range(len(times)):
#         for lata in range(len(lat)):
#             for lono in range(len(lon)):
#
#                 # print "time :"+times[timets].strftime("%Y-%m-%d %H:%M:%S")
#                 # print "lat :" + lat[lata]
#                 # print "lon :" + lon[lono]
#                 # print "mrt :" + mrt[timets][lata][lono]
#                 # timets.strftime("%Y-%m-%d %H:%M:%S")
#                 ice_writer.writerow([str(times[timets].strftime("%Y-%m-%d %H:%M:%S")), str(lat[lata]), str(lon[lono]), str(mrt[timets][lata][lono])])
#                 # print "000"
#
#
#     #
#     # ice_writer.writerow(['2019-01-01T24:00:00Z', '90', '-180', '247.98065'])
#     # ice_writer.writerow(['2019-01-02T24:00:00Z', '91', '-110', '240.98065'])
#
#     # ice_writer.close()
#
# ice_file.close()

#
#
# print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
#
# mrt_arr = mrt[:]
# print mrt_arr.shape
# print lon.shape
# print lon[0]
# print lat[0]
# print time[0]
# print mrt_arr[0][0][0]
